package base.java9_17;

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;

/**
 * @author 王霄
 * @date 2021/9/15 23:13
 */
public class HttpClientDemo {
    public static void main(String[] args) {
        var httpClient = HttpClient.newBuilder()
                .connectTimeout(Duration.ofSeconds(10))
                .build();
        var request = HttpRequest.newBuilder()
                .uri(URI.create("http://localhost:8081/test"))
                .timeout(Duration.ofSeconds(10))
                .header("Cookie" , "aid=ABC;userId=00001")
                .GET()
                .build();
        String body = httpClient
                .sendAsync(request, HttpResponse.BodyHandlers.ofString())
                .join()
                .body();
        System.out.println(body);
    }
}
